package com.ibeeking.found.upms.api.feign.fallback;

import com.ibeeking.found.upms.api.common.dto.TenantListDTO;
import com.ibeeking.found.upms.api.feign.GlobalTenantClient;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class GlobalTenantFallbackFactory implements FallbackFactory<GlobalTenantClient> {
    @Override
    public GlobalTenantClient create(Throwable throwable) {
        return new GlobalTenantClient() {
            @Override
            public ResponseResult<List<TenantListDTO>> queryUserTenantsByIds(List<Integer> ids) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询租户信息失败。" + throwable.getMessage(), Collections3.emptyList());
            }
        };
    }
}
